package com.fr.report.adhoc;

import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.core.json.JSONArray;
import com.fr.base.core.json.JSONObject;
import com.fr.base.file.DatasourceManager;
import com.fr.data.TableData;
import com.fr.data.condition.Condition;
import com.fr.data.condition.ListCondition;

public abstract class NormalADHOCReport
  implements ADHOCReport
{
  private String viewName;
  private String title;
  private String subtitle;
  private ADHOCSummaryColumn summaryColumn;
  private Condition condition;

  public TableData getADHOCData()
  {
    if (StringUtils.isEmpty(getViewName()))
      return null;
    return FRContext.getDatasourceManager().getADHOC(getViewName());
  }

  public String getViewName()
  {
    return this.viewName;
  }

  public void setViewName(String paramString)
  {
    this.viewName = paramString;
  }

  public String getTitle()
  {
    return this.title;
  }

  public void setTitle(String paramString)
  {
    this.title = paramString;
  }

  public String getSubtitle()
  {
    return this.subtitle;
  }

  public void setSubtitle(String paramString)
  {
    this.subtitle = paramString;
  }

  public ADHOCSummaryColumn getSummaryColumn()
  {
    return this.summaryColumn;
  }

  public void setSummaryColumn(ADHOCSummaryColumn paramADHOCSummaryColumn)
  {
    this.summaryColumn = paramADHOCSummaryColumn;
  }

  public Condition getCondition()
  {
    return this.condition;
  }

  public void setCondition(Condition paramCondition)
  {
    this.condition = paramCondition;
  }

  public JSONObject createJSON()
    throws Exception
  {
    return null;
  }

  public void parseJSON(JSONObject paramJSONObject)
    throws Exception
  {
    if (paramJSONObject.has("title"))
      setTitle(paramJSONObject.getString("title"));
    if (paramJSONObject.has("subtitle"))
      setSubtitle(paramJSONObject.getString("subtitle"));
    setViewName(paramJSONObject.getString("viewname"));
    if (paramJSONObject.has("summaryColumn"))
      try
      {
        ADHOCSummaryColumn localADHOCSummaryColumn = new ADHOCSummaryColumn();
        localADHOCSummaryColumn.parseJSON(paramJSONObject.getJSONArray("summaryColumn").getJSONObject(0));
        setSummaryColumn(localADHOCSummaryColumn);
      }
      catch (Exception localException)
      {
      }
    if (paramJSONObject.has("condition"))
    {
      ListCondition localListCondition = new ListCondition();
      localListCondition.parseJSON(paramJSONObject.getJSONObject("condition"));
      setCondition(localListCondition);
    }
  }
}